﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using iTextSharp.text;
using iTextSharp.text.pdf;

namespace mkrpt
{
    public class KesinKayitOlanReport:MakeReport
    {
        public KesinKayitOlanReport()
        {
            Doc = new Document(new Rectangle(842f, 595f));
        }

        public KesinKayitOlanReport(SaveFileDialog aDialog)
        {
            Doc = new Document(new Rectangle(842f, 595f));
            SaveDialog = aDialog;
        }
        void CreateOrcheckFolder(string path)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        }
        public override void Printreport(DataGridView aGridView,string title, int rowCount, params int[] column)
        {
            Fs = new FileStream(SaveDialog.FileName, FileMode.Create, FileAccess.Write, FileShare.Write);
            PdfWriter.GetInstance(Doc, Fs);
            ApTable = new PdfPTable(column.Count());
            //actual width of table in points
            ApTable.TotalWidth = 800f;
            //fix the absolute width of the table
            ApTable.LockedWidth = true;
            //relative col widths in proportions - 1/3 and 2/3
            var widths = new float[] { 3f, 3f ,4f,3f,4f,2f,3f,2f,4f};
            ApTable.SetWidths(widths);
            ApTable.HorizontalAlignment = 0;
            //leave a gap before and after the table
            ApTable.SpacingBefore = 30f;
            ApTable.SpacingAfter = 20f;
            ApCell = new PdfPCell(new Phrase(title));
            ApCell.Colspan = aGridView.ColumnCount;
            ApCell.Border = 0;
            ApCell.HorizontalAlignment = 1;
            ApCell.VerticalAlignment = 1;
            ApTable.AddCell(ApCell);
            for (int i = 0; i < rowCount; i++)
            {
                foreach (var j in column)
                {
                    //MessageBox.Show(Convert.ToString(aGridView[j, i].Value));
                    ApTable.AddCell(Convert.ToString(aGridView[j, i].Value));
                }
            }
            Doc.Open();
            Doc.AddHeader("Kesin olan ogrecilerin listesi", "");
            Doc.Add(new Phrase("Liste"));
            Doc.Add(ApTable);
            Doc.Close();
            Fs.Close();
        }

        public override void Printreport(DataGridView dataGridView1, string title)
        {
            throw new NotImplementedException();
        }


        public string Path
        {
            get { return Application.StartupPath + "\\Report\\KesinKayitOlanReport.pdf"; }
        }
    }
}
